package com.mh.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mh.dto.R;
import com.mh.pojo.AuctionCourse;
import com.mh.service.AuctionCourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (AuctionCourse)表控制层
 *
 * @author zmh
 * @since 2023-08-07 11:39:19
 */
@RestController
@Slf4j
@CrossOrigin
@RequestMapping("/auctionCourses")
public class AuctionCourseController {
    /**
     * 服务对象
     */
    @Autowired
    private AuctionCourseService auctionCourseService;

    /**
     * 分页查询
     *
     * @param page 查询页数
     * @param size 一页显示条数
     * @return ·
     */
    @GetMapping("/page")
    public R<Page<AuctionCourse>> getAllByPage(int page, int size) {
        Page<AuctionCourse> auctionCoursePage = new Page<>(page, size);
        LambdaQueryWrapper<AuctionCourse> queryWrapper = new LambdaQueryWrapper<>();
        //TODO 查询条件定制

        //执行查询
        auctionCourseService.page(auctionCoursePage);
        return R.success(auctionCoursePage);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public R<AuctionCourse> selectOne(@PathVariable Serializable id) {
        return R.success(this.auctionCourseService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param auctionCourse 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R<String> insert(@RequestBody AuctionCourse auctionCourse) {
        return R.success(this.auctionCourseService.save(auctionCourse) + "");
    }

    /**
     * 修改数据
     *
     * @param auctionCourse 实体对象
     * @return 修改结果
     */
    @PutMapping
    public R<String> update(@RequestBody AuctionCourse auctionCourse) {
        return R.success(this.auctionCourseService.updateById(auctionCourse) + "");
    }

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") String id) {
        return R.success(this.auctionCourseService.removeById(id) + "");
    }


}

